﻿using System;
using System.IO;
using iTextSharp.text.pdf;

using System.Windows.Forms;


namespace printApodiksiC
{
    public class Class1
    {
         private static string pdfTemplate = @"D:\lianikiTeliko.pdf";
         private static string newFile = @"D:\lianikiTeliko2.pdf";

        //private static string pdfTemplate = "lianikiTeliko.pdf";
        //private static string newFile = "lianikiTeliko2.pdf";

        public void fillApodiksi(String eponimia,String epaggelma,String diefthinsi,
            String tk,String poli,String tilefono,String afm,String epitheto,String epaggelma2,
            String diefthinsi2,String tk2,String poli2,String tilefono2,String afm2, String proionta, 
            String synolikiTi )
        {
            PdfReader pdfReader = new PdfReader(pdfTemplate);
            PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(
            newFile, FileMode.Create));
            AcroFields pdfFormFields = pdfStamper.AcroFields;
            try
            {

                pdfFormFields.SetField("eponimia", eponimia);
                pdfFormFields.SetField("epaggelma", epaggelma);
                pdfFormFields.SetField("diefthinsi", diefthinsi);
                pdfFormFields.SetField("tk", tk);
                pdfFormFields.SetField("poli", poli);
                pdfFormFields.SetField("tilefono", tilefono);
                pdfFormFields.SetField("afm", afm);
                pdfFormFields.SetField("epitheto", epitheto );
                pdfFormFields.SetField("epaggelma2", epaggelma2);
                pdfFormFields.SetField("diefthinsi2", diefthinsi2);
                pdfFormFields.SetField("tk2", tk2);
                pdfFormFields.SetField("poli2", poli2);
                pdfFormFields.SetField("tilefono2", tilefono2);
                pdfFormFields.SetField("afm2", afm2);

                pdfFormFields.SetField("genikoSinolo", synolikiTi);

                string[] agoraP = proionta.Split('-');
                int temp = 1;

                for (int i = 0; i < agoraP.Length-1; i++)
                {
                    string[] agoraItems = agoraP[i].Split(',');
                    
                    pdfFormFields.SetField("posotita" + temp, agoraItems[0]);
                    pdfFormFields.SetField("proion" + temp, agoraItems[1]);
                    pdfFormFields.SetField("timiMonadas" + temp, agoraItems[2]);
                    pdfFormFields.SetField("sinolo" + temp, agoraItems[3]);
                    temp++;
                    
                }
                pdfStamper.FormFlattening = false;
                pdfStamper.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                pdfStamper.FormFlattening = false;
                pdfStamper.Close();

            }
        }

     
        public void printApodiksi()
        {


        }
    }
}
